package com.cooper.slidingmenu.utils;

import com.cooper.scrapemedialib.R;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;

public class ConfirmDialog extends DialogFragment {

	public interface ConfirmDialogListener {

		public abstract void onConfirmDialogReturn(int which, boolean isOk);
	}

	public static ConfirmDialog newInstance(int which, String title, String msg) {
		ConfirmDialog result = new ConfirmDialog();
		Bundle bundle = new Bundle();
		bundle.putInt("WHICH", which);
		bundle.putString("TITLE", title);
		bundle.putString("MSG", msg);
		result.setArguments(bundle);
		return result;
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		return new AlertDialog.Builder(getActivity())
				.setIcon(R.drawable.ic_dialog_icon)
				.setTitle(getArguments().getString("TITLE"))
				.setMessage(getArguments().getString("MSG"))
				.setPositiveButton(R.string.alert_dialog_ok,
						new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								((ConfirmDialogListener) getActivity())
										.onConfirmDialogReturn(getArguments()
												.getInt("WHICH"), true);

							}
						})
				.setNeutralButton(R.string.alert_dialog_cancel,
						new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								((ConfirmDialogListener) getActivity())
										.onConfirmDialogReturn(getArguments()
												.getInt("WHICH"), false);

							}
						}).create();
	}
}
